-module(p34).
-compile(export_all).

main(Bound) -> main(3, Bound).

main(Bound1, Bound2) -> 
    [Num || Num <- lists:seq(Bound1, Bound2), 
            Num =:= sum_of_digits_factorials(Num)].

to_digit(Symbol) -> erlang:list_to_integer([Symbol]).

sum_of_digits_factorials(Number) ->
    SymbolsList = erlang:integer_to_list(Number),
    DigitsList = lists:map(fun to_digit/1, SymbolsList),
    FactorialsList = lists:map(fun factorial/1, DigitsList),
    lists:sum(FactorialsList).

factorial(0) -> 1;
factorial(N) -> factorial(N - 1) * N.
